<template>
	<view class="container">
		<u-toast ref="uToast" />
		<u-navbar :is-back="true" title="功能室" back-icon-color='#333333' height="50" :border-bottom="false">
		</u-navbar>
		<view class="top">
			<view class="topBox">
				<view v-for="(topItem,topIndex) in declare_list" :key="topIndex" :data-name="topIndex"
					@click="changeIndex" :class="[activeIndex==topIndex?'con':'']">
					<text></text>
					{{topItem}}
				</view>
			</view>
		</view>
		<view class="classroom" v-show="activeIndex==1">
			<u-toast ref="uToast" />
			<view class="function_room" :style="{borderColor:leftBorderColor,color:leftColor,background:leftBackground}"
				@click="changeColor(1)">
				功能室
			</view>
			<view class="conference_room"
				:style="{borderColor:centerBorderColor,color:centerColor,background:centerBackground}"
				@click="changeColor(2)">
				会议室
			</view>
			<view class="laboratory" :style="{borderColor:rightBorderColor,color:rightColor,background:rightBackground}"
				@click="changeColor(3)">
				实验室
			</view>
		</view>
		<view class="list" v-for="(item,index) in applyList" :key="index" :style="{height:changeHeight(1)}">
			<view class="per_process" :style="{height:changeHeight(2)}" @click="changePath(item)">
				<view class="top">
					<text :style="{background:changeBgcolor(item.status)}">{{changeLabel(item)}}</text>
					<text>{{changeTitle(item)}}</text>
					<text>{{item.start_time}}</text>
					<image src="../../static/tupian88.png" mode="widthFix"
						style="width:30rpx; margin-top:20rpx;margin-left:170rpx;" v-show="activeIndex==1"
						@click.stop="$toLink('../launch_application/launch_application', {name:item.name,meeting_id:item.meeting_room_id,genre:item.type,people:item.people,site:item.place,meeting_remark:item.remark})">
					</image>
				</view>
				<view class="center" v-show="activeIndex!=0">
					<image :src="changeImg()" mode="widthFix"></image>
					<text>{{changeCenterContent(item)}}</text>
				</view>
				<view class="bottom">
					<image src="../../static/tupian104.png" mode="widthFix"></image>
					<text>{{item.remark}}</text>
				</view>
			</view>
		</view>
		<u-loadmore :status="status" />
	</view>
</template>
<script>
	import request from '../../request.js'
	import time from '../../time.js'
	export default {
		data() {
			return {
				declare_list: ['我的申请', '功能室申请', '功能室审批'],
				activeIndex: 0,
				sign: '',
				apply_list: [], //我的申请
				leftBorderColor: '#2f96fe',
				leftColor: '#fff',
				leftBackground: '#2f96fe',
				centerBorderColor: '#F2F2F2',
				centerColor: '#666666',
				centerBackground: '#fff',
				rightBorderColor: '#F2F2F2',
				rightColor: '#666666',
				rightBackground: '#fff',
				examine_list: [], //功能室审批
				application_list: [], //功能室申请
				type_num: 1, //类型切换
				status: 'loading',
				page: 0,
				last_page: '',

			}
		},
		onLoad(e) {
			// if (e.function_id) {
			// 	this.activeIndex = e.function_id;
			// 	console.log('触发了123')
			// 	this.page = 0;
			// 	this.meetingLists(this.type_num, 1);
			// } else {
			// 	console.log('触发了吗')
			// 	this.myApply();
			// }
			this.myApply();
		},
		onReachBottom() { //滚动到底部触发该函数
			console.log('触发了吗')
			if (this.page >= this.last_page) {
				this.status = 'nomore';
				return
			} else {
				this.status = 'loading';
			} //如果大于最后一页那么就中断函数

			this.page = ++this.page;

			setTimeout(() => {
				switch (this.activeIndex) {
					case 0:
						this.myApply(this.page);
						break;
					case 1:
						this.meetingLists(this.type_num, this.page);
						break;
					default:
						this.applyLists(this.page);
				}
			}, 2000)
		},
		computed: {
			applyList() {
				switch (this.activeIndex) {
					case 0:
						if (this.apply_list) {
							return this.apply_list;
						} else {
							return [];
						}
						break;
					case 1:
						if (this.application_list) {
							return this.application_list;
						} else {
							return [];
						}
						break;
					case 2:
						if (this.examine_list) {
							return this.examine_list;
						} else {
							return [];
						}
						break;
				}

			}
		},
		methods: {
			changeImg() {
				let str = '';
				switch (this.activeIndex) {
					case 1:
						str = '../../static/tupian103.png'
						break;
					case 2:
						str = '../../static/tupian114.png'
						break;
				}
				return str;
			},
			changePath(param) {
				switch (this.activeIndex) {
					case 0:
						if (this.$classify(param.status, 2) == '待审核') {
							this.$toLink('../approval_pending/approval_pending', {
								id: param.apply_id
							});
						}
						break;
						// case 1:
						// 	break;
					case 2:
						this.$toLink('../handle_application/handle_application', {id: param.apply_id});
						break;
				}
			},
			changeHeight(param) {
				let str = '';
				if (param == 1) {
					switch (this.activeIndex) {
						case 0:
							str = '150rpx';
							break;
						case 1:
							str = '195rpx';
							break;
						case 2:
							str = '195rpx';
							break;
					}
				} else {
					switch (this.activeIndex) {
						case 0:
							str = '124rpx';
							break;
						case 1:
							str = '169rpx';
							break;
						case 2:
							str = '169rpx';
							break;

					}
				}
				return str;
			},
			changeLabel(param) {
				let tag = param;
				let str = "";
				switch (this.activeIndex) {
					case 0:
						str = this.$classify(tag.status, 2);
						break;
					case 1:
						str = tag.place;
						break;
					case 2:
						str = this.$classify(tag.status, 2);
						break;
				}
				return str;
			},
			changeBgcolor(param) {
				let str = param;
				let bgColor = '';
				switch (this.activeIndex) {
					case 0:
						bgColor = this.$classify(str, 1);
						break;
					case 1:
						bgColor = '#43DAC2';
						break;
					case 2:
						bgColor = this.$classify(str, 1);
						break;
				}
				return bgColor;
			},
			changeCenterContent(param) {
				let str = "";
				switch (this.activeIndex) {
					case 1:
						str = param.place;
						break;
					case 2:
						str = param.teacher_user_info ? param.teacher_user_info.full_name : '';
						break;
				}
				return str;
			},
			changeTitle(param) {
				let str = "";
				switch (this.activeIndex) {
					case 0:
						str = param.meeting_room_detail ? param.meeting_room_detail.name : '';
						break;
					case 1:
						str = param.name;
						break;
					case 2:
						str = param.meeting_room_detail ? param.meeting_room_detail.name : '';
						break;
				}
				return str;
			},
			changeIndex(e) {
				console.log(e.currentTarget.dataset.name);
				let index = e.currentTarget.dataset.name;
				this.activeIndex = index;
				switch (this.activeIndex) {
					case 0:
						//切换的时候让页数重新变为零,用于标识页面状态的值也要变为原始值
						this.page = 0;
						this.myApply(1);
						break;
					case 1:
						//切换的时候让页数重新变为零,用于标识页面状态的值也要变为原始值
						this.page = 0;
						this.meetingLists(this.type_num, 1);
						break;
					default:
						//切换的时候让页数重新变为零,用于标识页面状态的值也要变为原始值
						this.page = 0;
						this.applyLists(1);
				}
			},
			changeColor(param) {
				switch (param) {
					case 1:
						if (this.leftBorderColor == '#F2F2F2') {
							this.leftBorderColor = '#2f96fe';
							this.leftColor = '#fff';
							this.leftBackground = '#2f96fe';
							this.centerBorderColor = '#F2F2F2';
							this.centerColor = '#666666';
							this.centerBackground = '#fff';
							this.rightBorderColor = '#F2F2F2';
							this.rightColor = '#666666';
							this.rightBackground = '#fff';
							this.page = 0;
							this.meetingLists(1, 1);
							this.type_num = 1;
						} else {
							this.leftBorderColor = '#F2F2F2';
							this.leftColor = '#666666';
							this.leftBackground = '#fff';
						}
						break;
					case 2:
						if (this.centerBorderColor == '#F2F2F2') {
							this.centerBorderColor = '#2f96fe';
							this.centerColor = '#fff';
							this.centerBackground = '#2f96fe';
							this.leftBorderColor = '#F2F2F2';
							this.leftColor = '#666666';
							this.leftBackground = '#fff';
							this.rightBorderColor = '#F2F2F2';
							this.rightColor = '#666666';
							this.rightBackground = '#fff';
							this.page = 0;
							this.meetingLists(2, 1);
							this.type_num = 2;
						} else {
							this.centerBorderColor = '#F2F2F2';
							this.centerColor = '#666666';
							this.centerBackground = '#fff';
						}
						break;
					case 3:
						if (this.rightBorderColor == '#F2F2F2') {
							this.rightBorderColor = '#2f96fe';
							this.rightColor = '#fff';
							this.rightBackground = '#2f96fe';
							this.leftBorderColor = '#F2F2F2';
							this.leftColor = '#666666';
							this.leftBackground = '#fff';
							this.centerBorderColor = '#F2F2F2';
							this.centerColor = '#666666';
							this.centerBackground = '#fff';
							this.page = 0;
							this.meetingLists(3, 1);
							this.type_num = 3;
						} else {
							this.rightBorderColor = '#F2F2F2';
							this.rightColor = '#666666';
							this.rightBackground = '#fff';
						}
						break;
				}
			},
			//我的申请
			myApply(param) {
				let base_url = uni.getStorageSync('host');
				console.log(base_url);
				let _this = this;
				let pagination = param ? param : 1;
				request({
					url: base_url + 'teacher/meeting_room/myApply',
					method: 'post',
					data: {
						status: 0,
						page: pagination,
					},
					success(res) {
						if (res.statusCode == 200) {
							console.log(res);
							console.log(res.data.data.data, res.data.data.last_page);
							_this.last_page = res.data.data.last_page;
							if (res.data.data.total == 0) {
								console.log('又触发吗');
								_this.status = 'nomore'
								//如果接口返回的数据为零的话，那么就中断函数
								_this.apply_list.length = 0;
								//没有数据的话那么就将数组清空
								_this.apply_list = [];
								return;
							};
							//页数为1的情况
							if (pagination == 1) {
								//先将原数组清空
								_this.apply_list = [];
								console.log('进来了吗');
								if (res.data.data.data == null) {
									console.log('执行到这了吗')
									_this.apply_list = [];
								} else {
									_this.apply_list = res.data.data.data;
								}
								console.log(_this.apply_list);
								_this.page = 1;
								if (pagination >= _this.last_page) {
									_this.status = 'nomore'
									return
								}
								//页数大于1的情况
							} else if (pagination > 1) {
								console.log(res.data.data.data);
								if (res.data.data.data == null) {
									_this.status = 'nomore'
								}
								_this.apply_list = [..._this.apply_list, ...res.data.data.data];
								console.log(_this.apply_list);
								if (pagination >= _this.last_page) {
									_this.status = 'nomore'
									return
								}
							}
							console.log(_this.apply_list);
						} else {
							_this.$refs.uToast.show({
								title: res.data.message || '系统错误',
								type: 'warning',
							})
						}

					}
				})
			},
			//功能室申请
			meetingLists(param, param2) {
				let _this = this;
				let base_url = uni.getStorageSync('host');
				let str = this.$classroom(param);
				let pagination = param2 ? param2 : 1;
				let obj = {
					type: str
				};
				request({
					url: base_url + 'teacher/meeting_room/lists',
					method: 'post',
					data: {
						...obj,
						page: pagination,
					},
					success(res) {
						if (res.statusCode == 200) {
							console.log(res);
							console.log(res.data.data.data, res.data.data.last_page);
							_this.last_page = res.data.data.last_page;
							if (res.data.data.total == 0) {
								console.log('又触发吗');
								_this.status = 'nomore'
								//如果接口返回的数据为零的话，那么就中断函数
								_this.application_list.length = 0;
								//没有数据的话那么就将数组清空
								_this.application_list = [];
								return;
							};
							//页数为1的情况
							if (pagination == 1) {
								//先将原数组清空
								_this.application_list = [];
								console.log('进来了吗');
								if (res.data.data.data == null) {
									console.log('执行到这了吗')
									_this.application_list = [];
								} else {
									_this.application_list = res.data.data.data;
								}
								console.log(_this.application_list);
								_this.page = 1;
								if (pagination >= _this.last_page) {
									_this.status = 'nomore'
									return
								}
								//页数大于1的情况
							} else if (pagination > 1) {
								console.log(res.data.data.data);
								if (res.data.data.data == null) {
									_this.status = 'nomore'
								}
								_this.application_list = [..._this.application_list, ...res.data.data.data];
								console.log(_this.application_list);
								if (pagination >= _this.last_page) {
									_this.status = 'nomore'
									return
								}
							}
							console.log(_this.application_list);

						} else {
							_this.$refs.uToast.show({
								title: res.data.message || '系统错误',
								type: 'warning',
							})
						}

					}
				})
			},
			//功能室审批
			applyLists(param) {
				let base_url = uni.getStorageSync('host');
				console.log(base_url);
				let _this = this;
				let pagination = param ? param : 1;
				request({
					url: base_url + 'teacher/meeting_room/applyLists',
					method: 'post',
					data: {
						status: 0,
						page: pagination,
					},
					success(res) {
						if (res.statusCode == 200) {
							console.log(res.data.data.data);
							_this.examine_list = res.data.data.data;

							console.log(res);
							console.log(res.data.data.data, res.data.data.last_page);
							_this.last_page = res.data.data.last_page;
							if (res.data.data.total == 0) {
								console.log('又触发吗');
								_this.status = 'nomore'
								//如果接口返回的数据为零的话，那么就中断函数
								_this.examine_list.length = 0;
								//没有数据的话那么就将数组清空
								_this.examine_list = [];
								return;
							};
							//页数为1的情况
							if (pagination == 1) {
								//先将原数组清空
								_this.examine_list = [];
								console.log('进来了吗');
								if (res.data.data.data == null) {
									console.log('执行到这了吗')
									_this.examine_list = [];
								} else {
									_this.examine_list = res.data.data.data;
								}
								console.log(_this.examine_list);
								_this.page = 1;
								if (pagination >= _this.last_page) {
									_this.status = 'nomore'
									return
								}
								//页数大于1的情况
							} else if (pagination > 1) {
								console.log(res.data.data.data);
								if (res.data.data.data == null) {
									_this.status = 'nomore'
								}
								_this.examine_list = [..._this.examine_list, ...res.data.data.data];
								console.log(_this.examine_list);
								if (pagination >= _this.last_page) {
									_this.status = 'nomore'
									return
								}
							}
							console.log(_this.examine_list);
						} else {
							_this.$refs.uToast.show({
								title: res.data.message || '系统错误',
								type: 'warning',
							})
						}

					}
				})
			},
			redirection(param) {
				switch (param) {
					case 1:
						this.$toLink('../approval_pending/approval_pending');
						break;
					case 2:
						this.$toLink('../passed/passed');
						break;
				}
			}
		}
	}
</script>

<style lang="scss">
	.container {
		width: 100%;
		overflow: hidden;

		.classroom {
			height: 110rpx;
			width: 100%;
			display: flex;
			align-items: center;
			justify-content: flex-start;
			border-bottom: 1px solid #F2F2F2;

			.function_room {
				width: 129rpx;
				height: 61rpx;
				display: flex;
				justify-content: center;
				border-radius: 12rpx;
				margin-left: 61rpx;
				color: #fff;
				box-sizing: border-box;
				font-size: 24rpx;
				border: 1rpx solid #2f96fe;
				background: #2f96fe;
				align-items: center;
			}

			.conference_room {
				width: 129rpx;
				height: 61rpx;
				margin-left: 120rpx;
				display: flex;
				justify-content: center;
				box-sizing: border-box;
				border-radius: 12rpx;
				color: #666666;
				font-size: 24rpx;
				background: #fff;
				border: 1rpx solid #F2F2F2;
				align-items: center;
			}

			.laboratory {
				width: 129rpx;
				height: 61rpx;
				margin-left: 120rpx;
				display: flex;
				justify-content: center;
				border-radius: 12rpx;
				box-sizing: border-box;
				color: #666666;
				font-size: 24rpx;
				border: 1rpx solid #F2F2F2;
				background: #fff;
				align-items: center;
			}

		}

		.top {
			width: 100%;
			height: 65rpx;
			background: #fff;
			overflow: hidden;

			.topBox {
				width: 100%;
				height: 65rpx;
				background: #fff;
				position: relative;
				display: flex;
				justify-content: space-evenly;
				border-bottom: 1px solid #F2F2F2;

				view {
					height: 65rpx;
					line-height: 65rpx;
					width: 150rpx;
					text-align: center;
					font-size: 30rpx;
					color: #fff;
					color: #333333;

					text {
						display: none;
					}


				}

				.con {
					position: relative;
					height: 65rpx;
					line-height: 65rpx;
					color: #2F96FE;
					width: 150rpx;

					text {
						display: block !important;
						position: absolute;
						width: 150rpx;
						height: 4rpx;
						background: #2F96FE;
						bottom: 0rpx;
						left: 0rpx;
					}
				}

			}
		}

		.list {
			width: 100%;
			height: 195rpx;
			overflow: hidden;

			.per_process {
				margin-top: 22rpx;
				margin-left: 20rpx;
				height: 169rpx;
				width: 710rpx;
				border-radius: 15rpx;
				box-shadow: 0px 1px 1px 1px #ccc;

				.top {
					width: 100%;
					height: 60rpx;
					display: flex;
					justify-content: flex-start;

					text {
						margin-top: 20rpx;

						&:nth-child(1) {
							background-color: #FFA100;
							background: rgb(67, 218, 194);
							width: 60rpx;
							margin-left: 20rpx;
							height: 30rpx;
							margin-top: 25rpx;
							border-radius: 8rpx;
							color: #fff;
							font-size: 16rpx !important;
							text-align: center;
							line-height: 30rpx;
						}

						&:nth-child(2) {
							color: #333333;
							margin-left: 20rpx;
							font-size: 28rpx;
							width: 380rpx;
							overflow: hidden;
						}

						&:nth-child(3) {
							color: #999999;
							font-size: 20rpx;
							margin-top: 25rpx;

						}

						&:nth-child(4) {
							margin-left: 20rpx;
							color: #999999;
							font-size: 20rpx;
							margin-top: 25rpx;
						}
					}

					.active {
						background: #FFA100 !important;
					}
				}

				.center {
					width: 100%;
					height: 45rpx;
					display: flex;
					justify-content: flex-start;

					image {
						&:nth-child(1) {
							margin-top: 15rpx;
							margin-left: 20rpx;
							width: 30rpx;
						}
					}

					text {
						&:nth-child(2) {
							margin-top: 15rpx;
							margin-left: 30rpx;
							font-size: 24rpx;
							color: #666666;
						}
					}
				}

				.bottom {
					width: 100%;
					height: 45rpx;
					display: flex;
					justify-content: flex-start;

					image {
						&:nth-child(1) {
							margin-top: 15rpx;
							margin-left: 20rpx;
							width: 30rpx;
						}
					}

					text {
						&:nth-child(2) {
							margin-top: 15rpx;
							margin-left: 30rpx;
							font-size: 24rpx;
							color: #666666;
						}
					}
				}
			}
		}
	}
</style>
